package com.datasecops.scannerservices.watermark;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.ArrayList;

/**
 * @author: GeXiaoLong
 * @time: 2023/2/2 17:13
 */
@Service
@Slf4j
public class OracleDB {
    @Resource
    private  ImportAndExport importAndExport;
     /**
      *Oracle数据库的CSV文件的相关操作
      * @Description
      * @author GeXiaoLong
      * @time 2023/2/14 11:23
      * @param
      * @return
      */
    public Integer oracleToCsv() throws ClassNotFoundException, SQLException, IOException {
        //（1）使用Java JDBC连接数据库：

        Class.forName("oracle.jdbc.driver.OracleDriver");

        String url = "jdbc:oracle:thin:@10.26.18.66:1521:orcl";

        String user = "root";

        String password = "1234567";

//        String DB = "SAMPLE";

        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        //（2）构建SQL查询语句，查询出所需要的数据：
        //然后使用JDBC获取表的建表语句：
        String mode = "root";
        String model= mode.toUpperCase();
        String tableName = "users";//这个是要改成动态的
        String sql = "SELECT * FROM " + "\"" + tableName + "\"";
        System.out.println(sql);
        //这个是表数据
        Statement stmt = conn.createStatement();

        //ResultSet rs = stmt.executeQuery(sql);//这个移动到下面了?


        //获取表的建表语句
        String sqls = "select dbms_metadata.get_ddl('TABLE'," + "\'" + tableName + "\'" + ") from dual";//这个语句是获取到Oracle完整的建表语句
        System.out.println(sqls);
        ResultSet rss = stmt.executeQuery(sqls);
        String tableSql = null;
        while (rss.next()) {
            tableSql = rss.getString(1);
            System.out.println(tableSql);
            System.out.println("---------------------------------------------------------------------------------------");
        }

        //最后使用正则表达式将Oracle的建表语句转换成MySQL的建表语句

        //将Oracle的建表语句转换成MySQL的建表语句
        //String s1 = convertToMysql(tableSql);

//        String mysqlTableSql = tableSql.replaceAll("NUMBER\\(\\d+,\\d+\\)", "decimal");
//        mysqlTableSql = mysqlTableSql.replaceAll("NUMBER", "int");
//        mysqlTableSql = mysqlTableSql.replaceAll("VARCHAR2", "varchar");
//        mysqlTableSql = mysqlTableSql.replaceAll("DATE", "datetime");
//        mysqlTableSql = mysqlTableSql.replaceAll("\\(\\d+\\)", "");
//        System.out.println(mysqlTableSql);


        //这个是表结构
        DatabaseMetaData metaData1 = conn.getMetaData();
        ResultSet pkInfo = metaData1.getPrimaryKeys(null, model, tableName);//这里的text后期要改成动态的
        System.out.println(pkInfo == null);
        StringBuilder surface = new StringBuilder("");
        String primary = null;
        // System.out.println(pkInfo.next());
        while (pkInfo.next()) {
            System.out.print("数据库名称:" + pkInfo.getString("TABLE_CAT") + "                  ");
            System.out.print("表名称:" + pkInfo.getString("TABLE_NAME") + "                  ");


            surface.append("CREATE TABLE");
            surface.append(" ");
            surface.append(pkInfo.getString("TABLE_NAME"));
            surface.append(" ");
            surface.append("(");
            surface.append("\n");


            System.out.print("主键列的名称:" + pkInfo.getString("COLUMN_NAME") + "                  ");
            primary = pkInfo.getString("COLUMN_NAME");
            System.out.print("类型:" + pkInfo.getString("PK_NAME") + "                  ");
            System.out.println("");
        }

        ResultSet tableInfo = metaData1.getColumns(null, model, tableName, null);
        while (tableInfo.next()) {
            // 表的名字
            System.out.print("表名:" + tableInfo.getString("TABLE_NAME") + "    ");
            // 列的名称
            System.out.print("列名:" + tableInfo.getString("COLUMN_NAME") + "    ");

            // 默认值
            System.out.print("默认值 :" + tableInfo.getString("COLUMN_DEF") + "  ");
            // 字段的类型
            System.out.print("字段的类型:" + tableInfo.getString("TYPE_NAME") + "   ");

            // 是否可以为空
            System.out.print("是否可以为空:" + tableInfo.getString("IS_NULLABLE") + "  ");

            // 是否为自增
            System.out.print("是否为自增:" + tableInfo.getString("IS_AUTOINCREMENT") + " ");
            // 字段说明
            System.out.print("字段说明:" + tableInfo.getString("REMARKS") + "  ");
            // 长度(有时候是错的)
            System.out.print("长度:" + tableInfo.getString("COLUMN_SIZE") + " ");
            surface.append(tableInfo.getString("COLUMN_NAME"));
            surface.append(" ");
            surface.append(tableInfo.getString("TYPE_NAME"));
            surface.append(" ");
            surface.append("(");
            if ("DATE".equalsIgnoreCase(tableInfo.getString("TYPE_NAME"))){
                surface.append(6);
            }else {
                surface.append(tableInfo.getString("COLUMN_SIZE"));
            }
            //surface.append(tableInfo.getString("COLUMN_SIZE"));
            surface.append(")");
            surface.append(" ");
            surface.append("COLLATE utf8mb4_unicode_ci");
            surface.append(" ");
            if ("NO".equalsIgnoreCase(tableInfo.getString("IS_NULLABLE"))) {
                surface.append("NOT NULL");
            } else {
                surface.append("DEFAULT NULL");
            }
            surface.append(" ");
            surface.append(",");
            surface.append("\n");
            System.out.println();
        }
        surface.append("PRIMARY KEY");
        surface.append(" ");
        surface.append("(");
        surface.append(primary);
        surface.append(")");
        surface.append(" ");
        surface.append("USING BTREE");
        surface.append("\n");
        surface.append(")");
        surface.append(" ");
        surface.append("ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
        //String s = surface.toString();
        String replace = surface.toString();
        replace = replace.replace("NVARCHAR2", "varchar");
        replace = replace.replace("NUMBER","int");
        replace = replace.replace("DATE","datetime");
        replace = replace.replace("RAW","blob");
        replace = replace.replace("CLOB","text");

        System.out.println(replace);


        //（3）将查询结果写入CSV文件：
        ResultSet rs = stmt.executeQuery(sql);
/*        OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream("P:\\text\\your_file.csv"),
                StandardCharsets.UTF_8);//win版的*/
        OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream("/root/your_file.csv"),
                StandardCharsets.UTF_8);
//        FileWriter fw = new FileWriter("P:\\text\\your_file.csv");
        ResultSetMetaData metaData = rs.getMetaData();
        int columeCount = metaData.getColumnCount();//
        String columnName = metaData.getColumnName(1);
        //String columnName = metaData.getColumnName(1);
        //System.out.println(columeCount);
        String String = "";

        for (int i = 1; i <= columeCount; i++) {
            if (!(i == columeCount)) {
                String = String + metaData.getColumnName(i) + ",";
            } else {
                String = String + metaData.getColumnName(i) + "\n";
            }
        }
        fw.append(String);
        //String outputString = "";
        while (rs.next()) {
            String outputString = "";
            for (int i = 1; i <= columeCount; i++) {
                if (!(i == columeCount)) {
                  /*  if("002ba075-7321-48cb-bbde-154d6d200096".equalsIgnoreCase(rs.getString(i))){
                        System.out.println("11111111111");
                    }*/
                    String str = rs.getString(i);
                    boolean b = rs.wasNull();
                    int i1 = -1;
                    if (str != null) {
                        i1 = str.indexOf("\n");//如果获取到的字符串中含有换位符\n ,那么i1的值就不是-1,只有不包含的时候才是-1;
                    }
                    if ( i1 != -1){
                        String replaces = null;
                        if (str != null){
                             replaces = str.replace("\n", "");//把自动生成的换位符去掉
                        }
                        outputString = outputString + replaces + ",";
                    }else {
                        if (b){
                            outputString = outputString  + "NULL"+",";
                        }else {
                            outputString = outputString + rs.getString(i) + ",";
                        }
                        //outputString = outputString + rs.getString(i) + ",";
                    }
                } else {
                    outputString = outputString + rs.getString(i) + "\n";
                }
            }
            //           String outputString = rs.getString(1) + "," + rs.getString(2) + "," + rs.getString(3) + "\n";

            fw.append(outputString);

        }

        fw.flush();

        fw.close();

        //（4）关闭数据库连接：

        rs.close();

        rss.close();

        stmt.close();

        conn.close();

        Integer integer = importData(replace, tableName, tableSql, user);
        return integer;
    }

    /**
     *创建新表和导入csv
     * @Description
     * @author GeXiaoLong
     * @time 2023/1/15 11:27
     * @param
     * @param tableName
     * @param tableSql
     * @param user
     * @return
     */
    public Integer importData(String surface, String tableName, String tableSql, String user) throws SQLException, IOException, ClassNotFoundException {
//        1. 使用JDBC驱动程序：
//        首先，我们需要准备一个JDBC驱动程序，例如MySQL Connector / J。该程序可以在MySQL的官方网站上下载。下载完成后，我们需要将其添加到我们的classpath中，以便可以在程序中使用它。
//        2. 建立与MySQL数据库的连接：
//        现在，我们可以编写代码来与MySQL数据库建立连接，使用JDBC驱动程序。以下是一个示例：
//        Statement st = null;
//        String url = "jdbc:mysql://10.26.18.58:3306/WatermarkingDatabase";
//        String user = "root";
//        String password = "Wzx.1104";
//
//        Connection con = DriverManager.getConnection(url, user, password);
//       st =  con.createStatement();
//
////        3. 使用LOAD DATA语句导入CSV文件：
////        现在，我们可以使用Java中的PreparedStatement对象来执行LOAD DATA语句，以便将CSV文件导入MySQL数据库。
//
        String loadDataQuery = " LOAD DATA LOCAL INFILE '/root/your_file.csv' INTO TABLE " +
                tableName +" FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES";//linux


      /*  String loadDataQuery = " LOAD DATA LOCAL INFILE 'P://text//your_files.csv' INTO TABLE " +
                tableName +" FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES";
*/
//
//        st.executeUpdate(loadDataQuery);
//        System.out.println(loadDataQuery);
//
//        PreparedStatement preparedStatement = con.prepareStatement(loadDataQuery);
//
//        preparedStatement.execute();

        log.error("数据库安装程序进来了吗?");
        Statement st = null;
        try {
            log.error("数据库安装程序运行进来了吗1?");
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://10.26.18.58:3306/mysql?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai";
            String username = "root";
            String password = "Wzx.1104";
            Connection c = DriverManager.getConnection(url, username, password);
            st = c.createStatement();
            st.executeUpdate("CREATE DATABASE IF NOT EXISTS WatermarkingDatabase");//创建数据库
            st.executeUpdate("USE WatermarkingDatabase");
            ResultSet resultSet = st.executeQuery("SHOW TABLES LIKE 'SOULWJ'");
            while (resultSet.next()){
                String string = resultSet.getString(1);
                System.out.println(string);
            }


            int i = st.executeUpdate(surface);//创建一张新表
            System.out.println(i);
            //rs = st.executeQuery("select * from student");
            System.out.println(loadDataQuery);

            //执行导入csv文件代码
            boolean execute = st.execute(loadDataQuery);
            int updateCount = st.getUpdateCount();
            while (!(updateCount > 0)){
                System.out.println("正在导入");
            }
            System.out.println(execute);//导入csv文件
//System.out.println(loadDataQuery);
            //st.executeUpdate( loadDataQuery);
            //st.execute(loadDataQuery);
        } catch (Exception e) {
            log.error("数据库添加程序运行失败,原因是: ",e);
        } finally {
            st.close();
        }

        log.error("加注水印的程序进来了吗1");
        Integer watermarking = watermarking(tableName, tableSql, user);

//        OracleDB oracleDB = new OracleDB();
//        oracleDB.watermarking();
        return watermarking;
    }

    /**
     *创建加注水印后的新库
     * @Description
     * @author GeXiaoLong
     * @time 2023/2/4 14:10
     * @param
     * @param tableName
     * @param tableSql
     * @param user
     * @return
     */
    public Integer watermarking(String tableName, String tableSql, String user) throws SQLException, IOException, ClassNotFoundException {
        //（1）使用Java JDBC连接数据库：

        Class.forName("oracle.jdbc.driver.OracleDriver");

        String url = "jdbc:oracle:thin:@10.26.18.66:1521:orcl";

        String users = "soul";

        String password = "1234567";

//        String DB = "SAMPLE";

        Connection conn = null;
        System.out.println(tableSql);
        try {
            conn = DriverManager.getConnection(url, users, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        //这个是表数据
        Statement stmt = conn.createStatement();
        String names = users.toUpperCase();
        String name = user.toUpperCase();
        String replace = tableSql.replace(name,names );//这里是换用户名
        System.out.println(replace);
        int i = stmt.executeUpdate(replace);//创建一张新表
        System.out.println(i);

        //（4）关闭数据库连接：
        stmt.close();
        conn.close();
        log.error("加注水印的程序进来了吗2");
        Integer text = importAndExport.text(tableName);
//        watermarkExport(tableName);
        Integer integer = ReadCSV();//csv文件的行数
        Integer integer1 = DBRows(tableName);//数据库导入的行数
        ArrayList<String> list = new ArrayList<>();
        log.error("对比行数出来了吗?");
        while ((integer-1) == integer1){
            log.error("对比行数前进来了吗?");
            list = watermarkExport(tableName);
            break;
        }
        watermarkingImport(list);

        return text;
    }
     /**
      *水印加注完后的导出(用csv方法)
      * @Description
      * @author GeXiaoLong
      * @time 2023/2/6 15:34
      * @param
      * @param tableName
      * @return
      *//*
    public void watermarkExport(String tableName) throws ClassNotFoundException, IOException, SQLException {
        Class.forName("oracle.jdbc.driver.OracleDriver");

        String url = "jdbc:oracle:thin:@10.26.18.66:1521:orcl";

        String user = "root";

        String password = "1234567";

//        String DB = "SAMPLE";

        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        //（3）将查询结果写入CSV文件：
        Statement stmt = conn.createStatement();
        //String tableName = "dlp_datarisksit_assessment_question_bank";
        String sql = "SELECT * FROM " + "\"" + tableName + "\"";
        ResultSet rs = stmt.executeQuery(sql);
//        OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream("P:\\text\\your_file.csv"),
//                StandardCharsets.UTF_8);//win版的
        OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream("/root/your_file.csv"),
                StandardCharsets.UTF_8);
//        FileWriter fw = new FileWriter("P:\\text\\your_file.csv");
        ResultSetMetaData metaData = rs.getMetaData();
        int columeCount = metaData.getColumnCount();//
        String columnName = metaData.getColumnName(1);
        //String columnName = metaData.getColumnName(1);
        //System.out.println(columeCount);
        String String = "";

        for (int i = 1; i <= columeCount; i++) {
            if (!(i == columeCount)) {
                String = String + metaData.getColumnName(i) + ",";
            } else {
                String = String + metaData.getColumnName(i) + "\n";
            }
        }
        fw.append(String);
        //String outputString = "";
        while (rs.next()) {
            String outputString = "";
            for (int i = 1; i <= columeCount; i++) {
                if (!(i == columeCount)) {
                  *//*  if("002ba075-7321-48cb-bbde-154d6d200096".equalsIgnoreCase(rs.getString(i))){
                        System.out.println("11111111111");
                    }*//*
                    String str = rs.getString(i);
                    boolean b = rs.wasNull();
                    System.out.println(b);
                    int i1 = -1;
                    if (str != null) {
                        i1 = str.indexOf("\n");//如果获取到的字符串中含有换位符\n ,那么i1的值就不是-1,只有不包含的时候才是-1;
                    }
                    if ( i1 != -1){
                        String replaces = null;
                        if (str != null){
                            replaces = str.replace("\n", "");//把自动生成的换位符去掉
                        }
                        outputString = outputString + replaces + ",";
                    }else {
                        if (b){
                            outputString = outputString  + "NULL"+",";
                        }else {
                            outputString = outputString + rs.getString(i) + ",";
                        }
                        //outputString = outputString + rs.getString(i) + ",";
                    }
                } else {
                    outputString = outputString + rs.getString(i) + "\n";
                }
            }
            //           String outputString = rs.getString(1) + "," + rs.getString(2) + "," + rs.getString(3) + "\n";

            fw.append(outputString);

        }

        fw.flush();

        fw.close();

        //（4）关闭数据库连接：

        rs.close();
        conn.close();

    }*/




    /**
     *水印加注完后的导出(用sql语句方法)
     * @Description
     * @author GeXiaoLong
     * @time 2023/2/6 15:34
     * @param
     * @param tableName
     * @return
     */
    public ArrayList<String> watermarkExport(String tableName) throws ClassNotFoundException, IOException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://10.26.18.58:3306/mysql?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "Wzx.1104";

//        String DB = "SAMPLE";

        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        //（3）将查询结果写入sql语句中：
        Statement stmt = conn.createStatement();
        //String tableName = "dlp_datarisksit_assessment_question_bank";
        String mode = "watermarkingdatabase";
//        //String tableName = "dlp_datarisksit_assessment_question_bank";
        String sql = "SELECT * FROM " + mode +"."+tableName;
        //String sql = "SELECT * FROM " +tableName;
        ResultSet rs = stmt.executeQuery(sql);
        StringBuilder stringBuilder = new StringBuilder("");
        ArrayList list = new ArrayList();
        ResultSetMetaData metaData = rs.getMetaData();
        int columeCount = metaData.getColumnCount();//
        String columnName = metaData.getColumnName(1);
        //String columnName = metaData.getColumnName(1);
        //System.out.println(columeCount);
        String string = "";

        for (int i = 1; i <= columeCount; i++) {
            if (!(i == columeCount)) {
                string = string + "\""+ metaData.getColumnName(i) + "\"" + ",";
            } else {
                string = string + "\"" + metaData.getColumnName(i)+ "\"" ;
            }
        }
        //String outputString = "";

        while (rs.next()) {
            String data = "";
            String outputString = "";
            for (int i = 1; i <= columeCount; i++) {
                if (!(i == columeCount)) {
                    String str = rs.getString(i);
                    boolean b = rs.wasNull();
                    //System.out.println(b);
                    int i1 = -1;
                    if (str != null) {
                        i1 = str.indexOf("\n");//如果获取到的字符串中含有换位符\n ,那么i1的值就不是-1,只有不包含的时候才是-1;
                    }
                    if ( i1 != -1){
                        String replaces = null;
                        if (str != null){
                            replaces = str.replace("\n", "");//把自动生成的换位符去掉
                        }
                        outputString = outputString + "\'" + replaces + "\'" + ",";
                    }else {
                        if (b){
                            outputString = outputString  + "NULL" +",";
                        }else {
                            outputString = outputString + "\'" + rs.getString(i) + "\'" + ",";
                        }
                        //outputString = outputString + rs.getString(i) + ",";
                    }
                } else {
                    outputString = outputString + "\'" + rs.getString(i) +"\'";
                    stringBuilder.append("INSERT INTO ");
                    stringBuilder.append("\"");
                    stringBuilder.append(tableName);
                    stringBuilder.append("\"");
                    stringBuilder.append("(");
                    stringBuilder.append(string);
                    stringBuilder.append(")");
                    stringBuilder.append(" VALUES ");
                    stringBuilder.append("(");
                    stringBuilder.append(outputString);
                    stringBuilder.append(")");
                    //stringBuilder.append(";");
                    stringBuilder.append("\n");
                    data = stringBuilder.toString();
                    //System.out.println(data);
                    list.add(data);
                    stringBuilder.setLength(0);//这是把stringBuilder的内容清空



                }
            }
            //           String outputString = rs.getString(1) + "," + rs.getString(2) + "," + rs.getString(3) + "\n";

            //stringBuilder.append(outputString);

        }

        //（4）关闭数据库连接：
        rs.close();
        conn.close();

        return list;
    }



     /**
      *获取csv文件的行数
      * @Description
      * @author GeXiaoLong
      * @time 2023/2/6 15:45
      * @param
      * @return
      */
    public Integer ReadCSV() {
        int count = 0;
        try {
            FileReader fr = new FileReader("/root/your_file.csv");
            BufferedReader br = new BufferedReader(fr);
            //count = 0;
            while (br.readLine() != null) {
                count++;
            }
            System.out.println("行数：" + count);
            br.close();
            fr.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return count;
    }

     /**
      *数据库导入的行数
      * @Description
      * @author GeXiaoLong
      * @time 2023/2/6 16:34
      * @param
      * @return
      */
    public Integer DBRows(String Name) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://10.26.18.58:3306/mysql?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "Wzx.1104";
        String tableName = Name ;
        String mode = "watermarkingdatabase";


        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        Statement stmt = conn.createStatement();

        String sql = "SELECT COUNT(*) FROM " +mode +"."+ tableName;



        ResultSet rs = stmt.executeQuery(sql);
        int count = 0;
        if (rs.next()) {
            count = rs.getInt(1);
        }
        return count;
    }

     /**
      *加注完水印后导回源库
      * @Description
      * @author GeXiaoLong
      * @time 2023/2/6 16:38
      * @param
      * @param sql
      * @return
      */
    public void watermarkingImport(ArrayList<String> sql) throws SQLException {

        log.error("数据库安装程序进来了吗?");
        Statement stmt = null;
        try {
            log.error("数据库安装程序运行进来了吗?");
            Class.forName("oracle.jdbc.driver.OracleDriver");

            String url = "jdbc:oracle:thin:@10.26.18.66:1521:orcl";

            String user = "soul";

            String password = "1234567";

            Connection conn = DriverManager.getConnection(url, user, password);
            //System.out.println(sql);
             stmt = conn.createStatement();
            for (String o : sql) {
                //System.out.println(o);
                int i = stmt.executeUpdate(o);
                //System.out.println(i);
            }
           // int i = stmt.executeUpdate(sql);
            //System.out.println(i);
        } catch (Exception e) {
            log.error("数据库添加程序运行失败,原因是: ",e);
        } finally {
            stmt.close();
        }

        log.error("加注水印的程序进来了吗3");
//        OracleDB oracleDB = new OracleDB();
//        oracleDB.watermarking();
    }









    public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
        String tableName = "dlp_datarisksit_assessment_question_bank";
        OracleDB oracleDB = new OracleDB();
//        oracleDB.watermarkExport(tableName);
//        oracleDB.DBRows();
        oracleDB.oracleToCsv();


        //oracleDB.OracleToCsv();

        String sqls = "INSERT INTO \"dlp_datarisksit_assessment_question_bank\"(\"ID\",\"Module\",\"Type\"," +
                "\"SerialNumber\",\"Question\",\"SelectorModel\",\"ClassesId\",\"State\",\"Indexes\") VALUES " +
                "('002ba075-7321-48cb-bbde-154d6d200065','数据安全保护影响评估','数据安全保护义务','2.1'," +
                "'在开展数据处理活动中，是否依照法律、法规的规定，建立健全全流程数据安全管理制度，','满足/不满足/部分满足/不适用','3','NULL','5');";
        ArrayList s = oracleDB.watermarkExport(tableName);
        //oracleDB.soulss(s);
        oracleDB.watermarkingImport(s );
        String tableSql = "  CREATE TABLE \"ROOT\".\"dlp_datarisksit_assessment_question_bank\" \n" +
                "   (\t\"ID\" NVARCHAR2(36) NOT NULL ENABLE, \n" +
                "\t\"Module\" NVARCHAR2(36) NOT NULL ENABLE, \n" +
                "\t\"Type\" NVARCHAR2(36) NOT NULL ENABLE, \n" +
                "\t\"SerialNumber\" NVARCHAR2(36) NOT NULL ENABLE, \n" +
                "\t\"Question\" NVARCHAR2(256) NOT NULL ENABLE, \n" +
                "\t\"SelectorModel\" NVARCHAR2(36) NOT NULL ENABLE, \n" +
                "\t\"ClassesId\" NVARCHAR2(36) NOT NULL ENABLE, \n" +
                "\t\"State\" NVARCHAR2(256), \n" +
                "\t\"Indexes\" NUMBER(6,0), \n" +
                "\t PRIMARY KEY (\"ID\")\n" +
                "  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS \n" +
                "  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n" +
                "  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1\n" +
                "  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n" +
                "  TABLESPACE \"DSM\"  ENABLE, \n" +
                "\t CONSTRAINT \"classessId\" FOREIGN KEY (\"ClassesId\")\n" +
                "\t  REFERENCES \"ROOT\".\"dlp_datarisksit_assessment_question_classes\" (\"ID\") ON DELETE SET NULL " +
                "ENABLE\n" +
                "   ) SEGMENT CREATION IMMEDIATE \n" +
                "  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 \n" +
                " NOCOMPRESS LOGGING\n" +
                "  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n" +
                "  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1\n" +
                "  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n" +
                "  TABLESPACE \"DSM\" ";


        System.out.println(tableSql);
        String replace = tableSql.replace("ROOT", "SOUL");
        System.out.println("============================================================================");
        System.out.println(replace);
        Integer integer = oracleDB.ReadCSV();
        System.out.println(integer);
        //Integer integer1 = oracleDB.DBRows();
        //System.out.println(integer1);

        //oracleDB.watermarkingImport(tableName);
        // oracleDB.watermarking(tableName, replace);

    }
    public void soulss(String s) throws IOException {
        FileWriter fileWriter = new FileWriter("P:\\text\\your_file.txt");
        fileWriter.write(s);
        fileWriter.flush();
        fileWriter.close();
    }

}
